package org.chnxi.study.concurrent.future.completeablefuture;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ForkJoinPool;
import java.util.concurrent.TimeUnit;

public class Demo2 {

    public static void main(String[] args) throws ExecutionException, InterruptedException {


        CompletableFuture<String> completableFuture1 = CompletableFuture.supplyAsync(() -> {
            System.out.println("supplyAsync=>"+Thread.currentThread().getName());
            return "aaa";
        });

        System.out.println("step1,这是主线程。。。"+Thread.currentThread().getName());

        CompletableFuture<String> completableFuture2= completableFuture1.thenApplyAsync(s -> {
            System.out.println("thenApply=》"+Thread.currentThread().getName());
                    return s + " bbb";
        });

        System.out.println("step2,这是主线程。。。"+Thread.currentThread().getName());

        CompletableFuture<Void> completableFuture3 = completableFuture2.thenAccept(System.out::println);

        System.out.println("step3,这是主线程。。。"+Thread.currentThread().getName());
        //completableFuture.get();
        Thread.sleep( 5 * 1000);
    }

}
